/**
 * 
 */
package com.dalonedrau.jogl.engine;

import java.awt.Dimension;

import javax.media.opengl.GLCapabilities;

/**
 * @author Donald
 */
public final class GameCanvas extends GameDrawable {
	/** serial id. */
	private static final long	serialVersionUID	= 1L;
	/** the map listener. */
	private GameCanvasListener	listener;
	/**
	 * Creates a new instance of COBCanvas.java.
	 * @param capabilities the graphics capabilities
	 * @param width the width of the canvas
	 * @param height the height of the canvas
	 */
	public GameCanvas(final GLCapabilities capabilities, final int width,
			final int height) {
		super(capabilities, null, null, null);
		super.setPreferredSize(new Dimension(width, height));
		listener = new GameCanvasListener(this);
		super.addGLEventListener(listener);
		super.addKeyListener(listener);
		super.addMouseListener(listener);
		super.setFocusable(true);
		super.setFocusTraversalKeysEnabled(false);
		Engine.getEngine().setScreen(this);
		super.setIgnoreRepaint(true);
		// super.requestFocus();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void display() {
		// reset the mouse position
		if (listener != null) {
			Interface.getInstance().setMouseLoc(
					super.getMousePosition());
		}
		super.display();
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void gameUpdate() {
		if (listener != null) {
			Interface.getInstance().setMouseLoc(
					super.getMousePosition());
			Interface.getInstance().gameUpdate();
		}
	}
	/**
	 * Gets the listener.
	 * @return {@link GameCanvasListener}
	 */
	public GameCanvasListener getListener() {
		return listener;
	}
	/**
	 * {@inheritDoc}
	 */
	@Override
	public void setTimeSpentInGame(final int time) {
		// TODO Auto-generated method stub

	}
}
